package com.Demo;


import utils.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class Demo02_update {
    public static void main(String[] args) {
        Connection connection = null;
        PreparedStatement statement= null;

        try {
            connection = DBUtil.getConnection();
            String sql = "update student set sno = ? where id = ?";
            statement = connection.prepareStatement(sql);

            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入修改后的学号:");
            String inputSno = scanner.next();
            System.out.println("请输入要修改的id:");
            long inputId = scanner.nextLong();

            statement.setString(1, inputSno);
            statement.setLong(2, inputId);

            int row = statement.executeUpdate();

            if (row == 1) {
                System.out.println("修改成功");
            } else {
                System.out.println("修改失败");
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.closeConnection(null, statement, connection);
        }

    }
}
